package cn.hj.basic.service.impl;



import cn.hj.basic.mapper.BaseMapper;
import cn.hj.basic.query.BaseQuery;
import cn.hj.basic.service.IBaseService;
import cn.hj.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;

    @Override
    @Transactional
    public void delete(Long id) {
        mapper.remove(id);
    }

    @Override
    public T findById(Long id) {
        return  mapper.selectById(id);
    }

    @Override
    public List<T> findAll() {
        return  mapper.selectAll();
    }

    @Override
    public PageList<T> selectData(BaseQuery query) {
        Long  total= mapper.count(query);
        List<T> rows = mapper.selectData(query);
        return new PageList<>(total,rows);
    }

    @Override
    @Transactional
    public void batchRemove(List<Long> ids) {
        mapper.batchdelete(ids);
    }

    @Override
    @Transactional
    public void insert(T t) {
        mapper.insert(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }
}
